package xiu_xiu.view_Ac_gold_annoucement;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.xiu_xiu.R;

import java.util.ArrayList;

import xiu_xiu.base.BaseFragment;
import xiu_xiu.utils.widget.CircleImageView;
import xiu_xiu.view_A_main.GoldAnnouncementActivity;
import xiu_xiu.view_A_main.RescueActivity;

/**
 * Created by 阳 on 2016/4/24.
 */
public class GoldAGoodPersonFragment extends BaseFragment {
    private ListView list;
    private ArrayList<ContentBref> listData = new ArrayList<>();
    private ListViewAdapter adapter;

    private GoldAnnouncementActivity activity;

    public GoldAGoodPersonFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        activity = (GoldAnnouncementActivity) getActivity();
        View view = inflater.inflate(R.layout.fragment_rescue, null);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initview();
        addData();
        setAdapter();

    }


    /**
     * 初始化
     */
    private void initview() {

        list = (ListView) getView().findViewById(R.id.lv_main_listview);
    }


    /**
     * 添加数据
     */
    private void addData() {
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));
        listData.add(new ContentBref(1, "", R.mipmap.woman));

    }

    /**
     * 设置adapter
     */
    private void setAdapter() {
        adapter = new ListViewAdapter();
        list.setAdapter(adapter);
    }

    /**
     * 处理监听
     */
    private void disposeListener() {
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });
    }


    class ListViewAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public ContentBref getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = activity.getLayoutInflater().inflate(R.layout.item_fragment_rescue_good_person, null);
                holder = new ViewHolder();
                holder.imageView = (CircleImageView) convertView.findViewById(R.id.image);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.imageView.setImageResource(listData.get(position).getImage());
            return convertView;
        }

        class ViewHolder {
            private TextView title;
            private CircleImageView imageView;
        }
    }

    /**
     * 实体类
     */
    class ContentBref {
        private int id;
        private String describe;
        private int image;

        public ContentBref() {
        }

        public ContentBref(int id, String describe, int image) {
            this.id = id;
            this.describe = describe;
            this.image = image;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getDescribe() {
            return describe;
        }

        public void setDescribe(String describe) {
            this.describe = describe;
        }

        public int getImage() {
            return image;
        }

        public void setImage(int image) {
            this.image = image;
        }
    }
}
